<template>
  <div class="brand-wrapper">
    <!--    搜索区域-->
    <div class="search-box">
      <el-form :inline="true" class="demo-form-inline" size="mini">
        <el-form-item label="菜单名称">
          <el-input v-model="searchForm.menuTitle" placeholder="请输入菜单名称"></el-input>
        </el-form-item>
        <el-form-item label="菜单类型">
          <el-select v-model="searchForm.menuType" placeholder="请选择菜单类型">
            <el-option label="目录" value="1"/>
            <el-option label="菜单" value="2"/>
            <el-option label="按钮" value="3"/>
          </el-select>
        </el-form-item>
        <el-date-picker
            v-model="chooseDate"
            style="width: 280px"
            type="datetimerange"
            :picker-options="pickerOptions"
            range-separator="-"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="yyyy-MM-dd HH:mm:ss"
            @change="chooseDateChange"
            size="mini"
            align="right">
        </el-date-picker>
        <el-form-item style="margin-left: 10px">
          <el-button type="primary" @click="searchPage">搜索</el-button>
          <el-button type="warning" @click="resetSearchForm">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <!--    操作区域  -->
    <div class="exec-box">
      <el-button type="primary" size="mini" @click="addBtnClick" v-hasperm="'system:menu:add'">新建</el-button>
      <el-button type="success" size="mini"
                 @click="createDialog=true,findById(selectId)" v-hasperm="'system:menu:edit'" :disabled="selectId==-1">编辑
      </el-button>
      <el-button type="danger" size="mini" @click="showBatchDeleteDialog" :disabled="selectId==-1" v-hasperm="'system:menu:batch'">删除</el-button>
    </div>
    <!--    数据表格-->
    <el-scrollbar>
      <el-table
          @row-click="rowClick"
          :data="tableData"
          row-key="id"
          highlight-current-row
          :tree-props="{children: 'children'}"
          style="width: 100%">
        <el-table-column
            prop="menuTitle"
            label="权限名称"
        >
        </el-table-column>
        <el-table-column
            prop="menuIcon"
            label="权限图标"
        >
          <template v-slot="obj">
            <e-icon :icon-name="obj.row.menuIcon"/>
          </template>
        </el-table-column>

        <el-table-column
            prop="sort"
            label="权限排序"
        >
        </el-table-column>

        <el-table-column
            prop="menuType"
            label="权限类型"
        >
          <template v-slot="obj">
            <el-tag v-if="obj.row.menuType==1">目录</el-tag>
            <el-tag type="success" v-if="obj.row.menuType==2">菜单</el-tag>
            <el-tag type="warning" v-if="obj.row.menuType==3">按钮</el-tag>
          </template>
        </el-table-column>

        <el-table-column

            prop="menuRouter"
            label="菜单路由"
        >
        </el-table-column>

        <el-table-column

            prop="perm_sign"
            label="权限标识"
        >
        </el-table-column>


        <el-table-column
            align="center"
            label="操作"
        >
          <template v-slot="obj">
            <el-button type="success" size="mini" @click.native.stop="findById(obj.row.id)" v-hasperm="'system:menu:edit'">编辑</el-button>
            <el-popconfirm
                style="margin-left: 8px"
                confirm-button-text='好的'
                cancel-button-text='不用了'
                icon="el-icon-info"
                @confirm="deleteById(obj.row.id)"
                icon-color="red"
                title="这是一段内容确定删除吗？"
            >
              <el-button slot="reference" size="mini" @click.native.stop type="danger" v-hasperm="'system:menu:delete'">删除</el-button>
            </el-popconfirm>

          </template>

        </el-table-column>

      </el-table>

      <!--    分页区域 -->
      <div class="page-box">
        <el-pagination
            background
            layout="prev, pager, next"
            @current-change="pageChange"
            :page-size="searchForm.pageSize"
            :current-page="searchForm.currentPage"
            :total="total">
        </el-pagination>
      </div>
    </el-scrollbar>

    <!--    新建弹框-->
    <el-dialog
        title="实体操作"
        :visible.sync="createDialog"
        width="40%">
      <el-form ref="form" label-width="80px" :model="formData" :rules="rules" label-position="middle" size="mini">
        <el-form-item label="上级权限" prop="parentId">
          <treeselect v-model="formData.parentId" :options="menuSelectList" :show-count="true" :normalizer="normalizer"
                      placeholder="请选择父亲"/>
        </el-form-item>

        <el-form-item label="权限类型" prop="menuType">
          <el-radio-group v-model="formData.menuType" size="small">
            <el-radio-button label="1">目录</el-radio-button>
            <el-radio-button label="2">菜单</el-radio-button>
            <el-radio-button label="3">按钮</el-radio-button>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="按钮图标" prop="menuIcon" v-if="formData.menuType!=3">
          <e-icon-picker v-model="formData.menuIcon" :options="options"/>
        </el-form-item>

        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="权限名称" prop="menuTitle">
              <el-input v-model="formData.menuTitle"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="权限排序" prop="sort">
              <el-input-number v-model="formData.sort" style="width: 100%" controls-position="right"
                               :min="1"></el-input-number>
            </el-form-item>
          </el-col>
        </el-row>


        <el-row :gutter="20">
          <el-col :span="12" v-if="formData.menuType!=1">
            <el-form-item label="权限标识" prop="permSign">
              <el-input v-model="formData.permSign"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="路由地址" prop="menuRouter" v-if="formData.menuType!=3">
              <el-input v-model="formData.menuRouter"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20" v-if="formData.menuType==2">
          <el-col :span="12">
            <el-form-item label="组件地址" prop="componentPath">
              <el-input v-model="formData.componentPath"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="组件名称" prop="componentName">
              <el-input v-model="formData.componentName"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

      </el-form>
      <span slot="footer" class="dialog-footer">
    <el-button @click="createDialog = false" size="mini">取 消</el-button>
    <el-button type="success" @click="addOrEdit" size="mini">确 定</el-button>
  </span>
    </el-dialog>
  </div>

</template>

<script src="./index.js"></script>

<style lang="scss">
@import "./index.scss";


</style>
